package com.baidu.unlockdemo

import android.animation.ValueAnimator
import android.os.Bundle
import androidx.activity.enableEdgeToEdge
import androidx.appcompat.app.AppCompatActivity
import androidx.core.view.ViewCompat
import androidx.core.view.WindowInsetsCompat
import com.baidu.unlockdemo.customview.LoginButton
import com.baidu.unlockdemo.databinding.ActivityAnimationLoginBinding

class AnimationLoginActivity : AppCompatActivity() , LoginButton.IOnAnimBtnClickListener{
    private lateinit var binding: ActivityAnimationLoginBinding
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        enableEdgeToEdge()
        binding = ActivityAnimationLoginBinding.inflate(layoutInflater)
        setContentView(binding.root)
        ViewCompat.setOnApplyWindowInsetsListener(findViewById(R.id.main)) { v, insets ->
            val systemBars = insets.getInsets(WindowInsetsCompat.Type.systemBars())
            v.setPadding(systemBars.left, systemBars.top, systemBars.right, systemBars.bottom)
            insets
        }

        //接收点击的回调事件
        /*
        binding.loginBtn.addOnClickCallback {
            //处理耗时任务
            ValueAnimator.ofFloat(0f, 1f).apply {
                duration = 1000
                addUpdateListener {
                    binding.loginBtn.setProgress(it.animatedValue as Float)
                }
            }.start()
        }
        */

        //binding.loginBtn.setIOnClickListener(this)
        //binding.loginBtn.setIOnClickListener(MyListener())
        binding.loginBtn.setIOnClickListener(object : LoginButton.IOnAnimBtnClickListener {
            override fun onClick() {
                //处理耗时任务
                ValueAnimator.ofFloat(0f, 1f).apply {
                    duration = 1000
                    addUpdateListener {
                        binding.loginBtn.setProgress(it.animatedValue as Float)
                    }
                }.start()
            }
        })

        binding.start.setOnClickListener {
            binding.musicWaveView.start()
        }
        binding.stop.setOnClickListener {
            binding.musicWaveView.stop()
        }
    }

    override fun onClick() {
        //处理耗时任务
        ValueAnimator.ofFloat(0f, 1f).apply {
            duration = 1000
            addUpdateListener {
                binding.loginBtn.setProgress(it.animatedValue as Float)
            }
        }.start()
    }
}

class MyListener: LoginButton.IOnAnimBtnClickListener{
    override fun onClick() {

    }
}